﻿Imports Mystery

''' <summary>
''' called by mistery to start with
''' </summary>
''' <remarks></remarks>
<GlobalAvalibleObject()>
Public Interface IStartScreen

    Event changeControlRequired(control As UserControl)

    Property control As UserControl

    Function getTitle() As String

End Interface

<GlobalAvalibleObjectImplementation(implementation_of:=GetType(IStartScreen), overrides_exsisting:=False, singleton:=True)>
Public Class DefaultStartScreen
    Implements IStartScreen

    Private Function getStartScreen() As System.Windows.Controls.UserControl
        Dim ms As MysterySession = getGlobalObject(Of MysterySession)()
        If ms.user Is Nothing Then
            Dim l As New Login
            AddHandler l.loginSuccefull, Sub() Me.control = New DefaultStartScreenControl
            Return l
        Else
            Return New DefaultStartScreenControl
        End If
    End Function

    Public Function getTitle() As String Implements IStartScreen.getTitle
        Return "Mistery"
    End Function

    Public Event changeControlRequired(control As UserControl) Implements IStartScreen.changeControlRequired

    Private _control As UserControl

    Public Property control As System.Windows.Controls.UserControl Implements IStartScreen.control
        Get
            If _control Is Nothing Then
                _control = getStartScreen()
            End If
            Return _control
        End Get
        Set(value As System.Windows.Controls.UserControl)
            If value Is Nothing Then Exit Property 'not allowed? for the moment not
            If value Is _control Then Exit Property
            _control = value
            RaiseEvent changeControlRequired(control)
        End Set
    End Property
End Class
